package com.wkbb.basic.utils;

import com.wkbb.basic.constant.BasicConstants;
import com.wkbb.common.business.BasicBusiness;
import com.wkbb.common.enums.RelationTypeEnum;
import com.wkbb.common.enums.RoleTypeEnum;
import com.wkbb.common.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;

import static com.wkbb.basic.constant.BasicConstants.*;

/**
 * @author Alger Yang
 * @date 2019/9/17 001716:55
 */
public class FillEmptyHeadImgUtil {

    private static final Logger logger = LoggerFactory.getLogger(FillEmptyHeadImgUtil.class);
    /**
     * 女性默认头像
     */
    private static List<String> females = Arrays.asList(DEFAULT_HEADIMG_TEACHER_FEMALE, DEFAULT_HEADIMG_PARENT_FEMALE, DEFAULT_HEADIMG_STUDENT_FEMALE);
    /**
     * 男性默认头像
     */
    private static List<String> males = Arrays.asList(DEFAULT_HEADIMG_TEACHER_MALE, DEFAULT_HEADIMG_PARENT_MALE, DEFAULT_HEADIMG_STUDENT_MALE);


    /**
     * 检查头像
     */
    public static String checkHeadImg(String sex, Integer roleType, String headImg, boolean isUpdate) {
        //若不是更新且无头像，使用默认头像
        if (!isUpdate) {
            if (StringUtil.isNullOrBlank(headImg)) {
                return switchDefaultHeadImg(roleType, sex);
            }
            //若原头像为男性默认头像且修改性别为女，切换为女头像
        } else if (!StringUtil.isNullOrBlank(headImg)) {
            //若原头像为女性默认头像且修改性别为男，切换为男头像
            if ((males.contains(headImg) && "女".equals(sex)) || (females.contains(headImg) && "男".equals(sex))) {
                return switchDefaultHeadImg(roleType, sex);
            }
        }

        return headImg;
    }

    private static String switchDefaultHeadImg(Integer roleType, String sex) {
        if (roleType == RoleTypeEnum.TEACHER.getValue()||roleType == RoleTypeEnum.EMPLOYEE.getValue()) {
            if ("女".equals(sex)) {
                return DEFAULT_HEADIMG_TEACHER_FEMALE;
            } else {
                return DEFAULT_HEADIMG_TEACHER_MALE;
            }
        } else if (roleType == RoleTypeEnum.FAMILY.getValue()) {
            if ("女".equals(sex)) {
                return BasicConstants.DEFAULT_HEADIMG_PARENT_FEMALE;
            } else {
                return BasicConstants.DEFAULT_HEADIMG_PARENT_MALE;
            }
        } else {
            if ("女".equals(sex)) {
                return BasicConstants.DEFAULT_HEADIMG_STUDENT_FEMALE;
            } else {
                return BasicConstants.DEFAULT_HEADIMG_STUDENT_MALE;
            }
        }
    }

    /**
     * 检查家长性别
     *
     * @param relationType 学生家长关系
     * @return
     */
    public static String checkFamilySex(Integer relationType) {
        List<Integer> male = Arrays.asList(RelationTypeEnum.FATHER.getValue(), RelationTypeEnum.GRANDPA.getValue(), RelationTypeEnum.MATERNAL_GRANDPA.getValue(),
                RelationTypeEnum.RELATIVE.getValue(),RelationTypeEnum.GRAND_FATHER.getValue(), RelationTypeEnum.OTHER.getValue());
        if (male.contains(relationType)) {
            logger.info("通过关系检查家长性别：" + relationType + " 男");
            return "男";
        } else {
            logger.info("通过关系检查家长性别：" + relationType + " 女");
            return "女";
        }

    }
}